import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getMovieListRequest } from '../../api/index'

export const  getMovieList = createAsyncThunk('movie/getMovieList', async () => {
    const re = await getMovieListRequest()
    return re.data.data.list
}
)

const movieSlice = createSlice({
    name: 'movie',
    initialState: {
        movieList: []
    },
    extraReducers: {
        [getMovieList.fulfilled](prev, {payload}) {
            console.log('请求成功');
            prev.movieList=payload
        },
        [getMovieList.rejected](prev, action) {
            console.log('请求失败');

        },
        [getMovieList.pending](prev, action) {
            console.log('请求进行中');
        },
    }
})

export default movieSlice.reducer